//
//  MasterTableViewController.swift
//  Cathy
//
//  Created by diandian on 14/12/9.
//  Copyright (c) 2014年 yangjie. All rights reserved.
//

import UIKit
import Alamofire

class MasterTableViewController: UITableViewController {
    
    var masterArr:[Master] = masterData

    override func viewDidLoad() {
        super.viewDidLoad()

        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem()
        
        //self.tableView.registerClass(MasterCell.classForCoder(), forCellReuseIdentifier: "MasterCellIdentifier")
        self.tableView.tableFooterView = UIView()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: - Table view data source

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        // #warning Potentially incomplete method implementation.
        // Return the number of sections.
        return 1
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete method implementation.
        // Return the number of rows in the section.
        return masterArr.count
    }


    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        var cell: MasterCell! = tableView.dequeueReusableCellWithIdentifier("MasterCellIdentifier", forIndexPath: indexPath) as MasterCell
        
        var master:Master = masterArr[indexPath.row] as Master
        
        cell.mainLabel?.text = master.title
        
        cell.infoLabel?.text = master.sub_title
        
        return cell
    }
    
    override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        return 60;
    }
    
    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        
        self.tableView.deselectRowAtIndexPath(indexPath, animated: true)
        
        var vc:DetailTableViewController = self.storyboard?.instantiateViewControllerWithIdentifier("DetailTableViewController") as DetailTableViewController
        self.navigationController?.pushViewController(vc, animated: true)
    }
}
